package com.weixing.mall.provider.service.impl;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weixing.mall.provider.mapper.BuySampleMapper;
import com.weixing.mall.provider.model.domain.BuySample;
import com.weixing.mall.provider.model.dto.BuySampleDto;
import com.weixing.mall.provider.model.query.BuySampleQuery;
import com.weixing.mall.provider.model.vo.BuySampleVo;
import com.weixing.mall.provider.service.IBuySampleService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author wx
 * @Date 2019/8/6 17:49
 * @Version 1.0
 */
/**
 * <p>
 * 商品模块-买板表 服务实现类
 * </p>
 *
 * @author Small
 * @since 2019-11-20
 */
@Service
public class BuySampleServiceImpl extends ServiceImpl<BuySampleMapper, BuySample> implements IBuySampleService {

    @Override
    public IPage<BuySampleVo> selectOfPage(Page page, BuySampleQuery buySampleQuery) {
        return baseMapper.selectList(page,buySampleQuery);
    }
    @Override
    public void save(BuySampleDto buySampleDto,Long uid) {
        BuySample buySample = new BuySample();
        BeanUtils.copyProperties(buySampleDto,buySample);
        buySample.setIsOnShelf(buySampleDto.getIsOnShelf().getValue());
        buySample.setIsTakePhoto(buySampleDto.getIsTakePhoto().getValue());
        buySample.setCreatedTime(DateUtil.parseDate(buySampleDto.getCreatedTime()));
        if(null==buySampleDto.getId()){
            buySample.setCreatedBy(uid);
            save(buySample);
        }else {
            buySample.setUpdatedBy(uid);
            updateById(buySample);
        }
    }
    @Override
    public void delAll(int[] ids) {
        baseMapper.delAll(ids);
    }

    @Override
    public void delById(Long id) {
        baseMapper.deleteById(id);
    }

    public void export() {


    }
    @Override
    public void batchInsertImportData(List<BuySample> list){
        saveBatch(list);
    }
}
